package com.dk.result;

import com.dk.enums.ResultEnum;

public class Result<T> {
    //返回的状态码
    private Integer code;
    //返回的提示信息
    private String message;
    //返回的数据(集合\类)
    private T data;

    //其他状态
    public static Result respones(ResultEnum re) {
        return new Result(re.getDataCode(), re.getMessage());
    }

    public static Result OK() {
        return new Result(ResultEnum.OK.getDataCode(), ResultEnum.OK.getMessage());
    }

    public static Result ER() {
        return new Result(ResultEnum.ER.getDataCode(), ResultEnum.ER.getMessage());
    }

    public static Result fallback(){
        return new Result(ResultEnum.FEIGN_FALLBACK.getDataCode(),ResultEnum.FEIGN_FALLBACK.getMessage());
    }
    public Result() {
    }

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public Result setData(T data) {
        this.data = data;
        return this;//当前对象
    }
}